<?php

require_once('Zend/Controller/Plugin/Abstract.php');

class My_Controller_Plugin_LoggedUser extends Zend_Controller_Plugin_Abstract {

	public function preDispatch(Zend_Controller_Request_Abstract $request) {
		
		$controller = $request->getControllerName();
		$action = $request->getActionName();
		
		$url = $controller . "/" . $action;
		
		$isPublic = ($url == "Activity/pageService" || url == "Activity/searchService" || $url == "login/register");
		
		if (!$isPublic && ($controller!='login' || $action!='index')){
			$auth = Zend_Auth::getInstance();
			if ($auth->hasIdentity()) {
				$request->setParam('loggedUser', $auth);
			}
			else{
				$request->setParam('errorMessage', 'Debe Iniciar Sesi�n.');
				$request->setControllerName('login');
				$request->setActionName('process');
			}
		}
		
	}

}
